/**
* @Title: auditFeedback_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEQI001
* @date 2014年11月19日 上午15:06:02
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('AuditFeedbackDetailCtrl', ['$scope', '$state','$stateParams','AuditFeedbackService','FwaTabsetService','Modal','BaseURL','CommunityService','$modal',
	                                       function($scope, $state,$stateParams,AuditFeedbackService,FwaTabsetService,Modal,baseUrl,CommunityService,$modal){
		
		var caseCode = $stateParams.caseCode;
		
		CommunityService.initDate("yyyy-MM-dd").success(function(res){
			$scope.formatDate  = res.formatDate;
		});
		
		$scope.loading = false;
		AuditFeedbackService.getAuditNotificationInfo(caseCode).success(function(res){
			$scope.caseDetail = res.result;
		});
		
		//返回
		$scope.revert = function() {
			FwaTabsetService.selectTab('auditFeedback');
		}
		
		//确定
		$scope.make = function() {
			$scope.loading = true;
			AuditFeedbackService.makeAuditFeedback(caseCode).success(function(res){
				Modal.alert(res.msg);
				if (res.state == '0') {
					$state.go('thisLetter.detail',{caseCode:caseCode});
				}
				$scope.loading = false;
			}).error(function(e){
				Modal.alert(e.msg);
				$scope.loading = false;
			});
		}
		
		/**
		 * 下载打印
		 */
		$scope.downLoadPdf = function() {
			var scope = $scope.$new();
			 var modalInstance = $modal.open({
			      templateUrl: baseUrl+'views/hcpms/audit/common/caseAuditTellReportDialog_view.html',
			      backdrop:'static',
				  size:'sm',
				  scope:scope,
				  controller: function($modalInstance,$scope){
					   $scope.$watch('$viewContentLoaded',function(){
			        		openpdf(); 	
					   	});
		      	    	  $scope.onOk = function(){
					  		   $modalInstance.dismiss();
					  	   }	
					  }
			    });
		}
		
	      //打开文件
        function  openpdf (){
  			var success = new PDFObject({ url:baseUrl+'auditDownFileController/downPdfFile.do?caseCode='+caseCode,
  				pdfOpenParams: { navpanes: 1,
                toolbar: 1,
                statusbar: 1,
                view: 'FitV',
                pagemode: 'thumbs'
  			}}).embed("caseAuditTellReportDialogOpenpdf");
  		  }
		
		//申诉
		$scope.appeal = function() {
			$scope.loading = true;
			AuditFeedbackService.appealAuditFeedback(caseCode).success(function(res){
				Modal.alert(res.msg);
				if (res.state == '0') {
					$state.go('thisLetter.detail',{caseCode:caseCode});
				}
				$scope.loading = false;
			}).error(function(e){
				Modal.alert(e.msg);
				$scope.loading = false;
			});
		}
		
	}]);
})();
